package com.deer.wms.base.system.service.zh.impl;

import com.deer.wms.base.system.dao.zh.DefectsTypeMapper;
import com.deer.wms.base.system.dao.zh.QualityMapper;
import com.deer.wms.base.system.model.zh.DefectsType;
import com.deer.wms.base.system.model.zh.Quality;
import com.deer.wms.base.system.model.zh.QualityDto;
import com.deer.wms.base.system.service.zh.QualityService;
import com.deer.wms.common.core.service.AbstractService;
import com.deer.wms.common.core.text.Convert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 李帅辰
 * @date 2021/5/29 17:47
 */
@Service
public class QualityServiceImpl extends AbstractService<Quality,Integer> implements QualityService {
    @Autowired
    private QualityMapper qualityMapper;

    @Autowired
    private DefectsTypeMapper defectsTypeMapper;

    @Override
    public QualityDto findQualityById(Integer qualityId) {
        return qualityMapper.findQualityById(qualityId);
    }

    @Override
    public QualityDto findQuality(Quality quality) {
        return qualityMapper.findQuality(quality);
    }

    @Override
    public List<QualityDto> findQualityList(Quality quality) {
        return qualityMapper.findQualityList(quality);
    }

    @Override
    public Quality findQualityByCode(String code) {
        return qualityMapper.findQualityByCode(code);
    }

    @Override
    public int delectQualityById(Integer qualityId) {
        return qualityMapper.delectQualityById(qualityId);
    }

    @Override
    public int delectQualityByIds(String qualityIds) {
        return qualityMapper.delectQualityByIds(Convert.toStrArray(qualityIds));
    }

    @Override
    public int saveQuality(Quality quality) {
        int i = qualityMapper.saveQuality(quality);
        List<DefectsType> defects = quality.getDefects();
        for (DefectsType defect : defects) {
            defect.setQualityId(quality.getQualityId());
            defectsTypeMapper.saveDefectsType(defect);
        }
        return i;
    }

    @Override
    public int updateQuality(Quality quality) {
        return qualityMapper.updateQuality(quality);
    }

    @Override
    public int updateResult(Quality quality) {
        return qualityMapper.updateResult(quality);
    }
}
